package com.xmx.interceptors;

import org.springframework.stereotype.Component;
import org.springframework.stereotype.Repository;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * overview：
 * author:
 * 2023年05月04日 13:08:
 */
@Component
public class CheckloginStatusInteceptor extends HandlerInterceptorAdapter {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        String servletPath = request.getServletPath();
        System.out.println("进到检查登录的iiiiiii");
        if("/page_login".equals(servletPath) || "/queryUserByConditions".equals(servletPath)){
            System.out.println("yemiammmmmmmmmmmmmmmmmmmmmmmmm");
            return true;

        }

        Object name = request.getSession().getAttribute("username");
        if(name == null || "".equals(name)){
            response.sendRedirect("page_login");
            return  false;
        }
        return true;

    }
}


